import { create } from 'zustand'
import { immer } from 'zustand/middleware/immer'
import { XAxisAttrsData } from './types'
import { UseAttrsPanelStoreFnc } from '@/store/model'


export const useXAxisStore = create<XAxisAttrsData & UseAttrsPanelStoreFnc, any>(
  immer((set) => ({
    show: true,
    name: 'X轴',
    nameLocation: 'end',
    nameGap: 15,
    nameRotate: 0,
    nameTruncate: {
      maxWidth: 100,
      ellipsis: '...',
    },
    nameTextStyle: {},
    position: 'bottom',
    offset: 0,
    alignTicks: true,
    boundaryGap: true,
    type: 'category',
    inverse: false,
    splitNumber: 5,
    gridIndex: 0,
    data: ['衬衫', '羊毛衫', '雪纺衫', '裤子', '高跟鞋', '袜子'],

    setAttrs: <T>(key: string, value: T) => set(() => ({ [key]: value })),
    setTextStylesAttrs: (key: string, value: any) => set((state) => {
      state.nameTextStyle[key] = value
      return state;
    })
  }))
) 